/*!
 * \file frhash_key.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frlist.h"
#include "frhash2.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    char *p_data = NULL;
    unsigned long hash_key = 0;

    hash_key = frhash_key((unsigned char *)p_data,0);

    CU_ASSERT_EQUAL(hash_key,0);
    frfree(p_data);

}

static void __case2(void)
{
    char *p_data = NULL;
    unsigned long hash_key = 0;

    p_data = (char *)frmalloc( 1);
    snprintf(p_data,1,"%s","\0");
    hash_key = frhash_key((unsigned char *)p_data,1);


    CU_ASSERT_EQUAL(hash_key,1364076727);

    frfree(p_data);

}

static void __case3(void)
{
    char *p_data = NULL;
    unsigned long hash_key = 0;

    p_data = (char *)frmalloc(strlen("test") + 1);
    snprintf(p_data,5,"%s","test");
    hash_key = frhash_key((unsigned char *)p_data,strlen("test"));

    CU_ASSERT_EQUAL(hash_key,3127628307);

    frfree(p_data);

}


int add_suite_frhash_key(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frhash2 frhash_key()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);

    return FR_SUCC;
}
